/**
 * @param {number[][]} matrix
 * @return {void} Do not return anything, modify matrix in-place instead.
 */
// 不占用额外空间，即交换两个值
// 数组先按右对角线进行折叠 --> 按折叠后的x轴进行反转
var rotate = function(matrix) {
    for (var i = 0; i < matrix.length; i++) {
        for (var j = 0; j < matrix[i].length - i - 1; j++) {
            var temp = matrix[i][j];
            matrix[i][j] = matrix[matrix.length - j - 1][matrix.length - i - 1];
            matrix[matrix.length - j - 1][matrix.length - i - 1] = temp;
        }
    }
    for (var i = 0; i < matrix.length/ 2; i++) {
        for (var j = 0; j < matrix.length; j++) {
            var temp = matrix[i][j];
            matrix[i][j] = matrix[matrix[i].length - i - 1][j];
            matrix[matrix[i].length - i - 1][j] = temp
        }
    }
};
console.log(rotate([
    [1,2,3],
    [4,5,6],
    [7,8,9]
]))
